<template>
  <div>
    <ul class="input" v-show="selectTop">
      <li>
        模糊搜索:
        <el-input
          placeholder=""
          v-model="input"
          clearable
          size="small "
        ></el-input>
      </li>
      <li>
        电话号码:
        <el-input
          placeholder=""
          v-model="searchValue.customerPhone"
          clearable
          size="small "
        ></el-input>
      </li>
      <li>
        车牌号码:
        <el-input
          placeholder=""
          v-model="searchValue.licensePlate"
          clearable
          size="small "
        ></el-input>
      </li>
      <li class="l_btn">
        <el-button
        type="primary"
        @click="search"
        icon="el-icon-search"
        size="small" >搜索</el-button
        >
        <el-button
          type="primary"
          icon="el-icon-refresh"
          size="small"
          @click="reset"
          style="background-color: #fff; border-color: #ddd; color: #606266"
          >重置</el-button
        >
      </li>
    </ul>
    <div class="btn">
      <Addapoint class="btn_l"></Addapoint>
      <!-- 重置刷新按钮 -->
    <div class="btn_r">
      <i @click="changetop" class="el-icon-search"></i>
      <i class="el-icon-refresh"></i>
    </div>
    </div>

    

    <!-- 用户表单 -->
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column
      type="selection"
      width="55">
    </el-table-column> -->
      <el-table-column label="客户姓名" width="80">
        <template slot-scope="{ row }">{{ row.customerName }}</template>
      </el-table-column>
      <el-table-column prop="name" label="联系方式" width="140">
        <template slot-scope="{ row }">{{ row.customerPhone }}</template>
      </el-table-column>
      <el-table-column prop="address" label="预约时间" show-overflow-tooltip>
        <template slot-scope="{ row }">{{ row.appointmentTime }}</template>
      </el-table-column>
      <el-table-column prop="address" label="到店时间" show-overflow-tooltip>
        <template slot-scope="{ row }">{{ row.actualArrivalTime }}</template>
      </el-table-column>
      <el-table-column prop="address" label="车牌号码" show-overflow-tooltip>
        <template slot-scope="{ row }">{{ row.licensePlate }}</template>
      </el-table-column>
      <el-table-column prop="address" label="汽车类型" show-overflow-tooltip>
        <template slot-scope="{ row }">{{ row.carSeries }}</template>
      </el-table-column>
      <el-table-column prop="address" label="服务类型" show-overflow-tooltip>
        <template slot-scope="{ row }">
          {{ row.serviceType == 1 ? "保养" : "维修" }}
        </template>
      </el-table-column>
      <el-table-column prop="address" label="备注" show-overflow-tooltip>
        <template slot-scope="{ row }">{{ row.info }}</template>
      </el-table-column>
      <el-table-column prop="address" label="状态" show-overflow-tooltip>
        <template slot-scope="{ row }">{{ row.status === "0" ? "预约中" : row.status == "1"?"已到店" : row.status=="2"?"用户取消":row.status=="4"?"结算单产生":"已支付" }}</template>
      </el-table-column>
      <el-table-column
        prop="address"
        label="操作"
        align="center"
        width="200"
        show-overflow-tooltip
      >
        <template>
          <i class="el-icon-edit" style="color: #1890ff">编辑</i>
          <i class="el-icon-delete" style="margin-left: 10px; color: #1890ff"
            >到店</i
          >
          <i class="el-icon-delete" style="margin-left: 10px; color: #1890ff"
            >结算单</i
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div
      style="display: flex; justify-content: flex-end; padding: 20px 20px 0 0"
    >
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="searchValue.pageNum"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { GetAppointmentApi,searchCustomeroApi } from "@/request/api";
import Addapoint from "@/components/userness/Addapoint.vue"

export default {
  data() {
    return {
      input: "",
      input:"",
      selectTop:true,
      tableData: [],
      multipleSelection: [],
      total: null,
      tel:'',
      searchValue:{
        // 当前页数
        pageNum: 1, 
        // 每页条数
        pageSize: 10, 
        // 关键词
        keyword:'',
        // 电话号码
        customerPhone:'',
        // 车牌号码
        licensePlate:'',
      }
    };
  },
  created() {
    this.getTableData();
  },
  methods: {
    async search(){
      let res=await searchCustomeroApi({...this.searchValue})
      if(!res) return
      this.tableData=res.rows
    },
    // 重置搜索框
    reset(){
      this.input="",
      this.searchValue.customerPhone="",
      this.searchValue.licensePlate="",
      this.getTableData()
    },
    changetop(){
      this.selectTop=!this.selectTop
    },
    handleSizeChange(val) {
      this.searchValue.pageSize = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      // 当前页数改变的时候执行
      console.log(`当前页: ${val}`);
      this.searchValue.pageNum = val;
      this.getTableData();
    },
    async getTableData() {
      const GetAppointmentApiRes = await GetAppointmentApi({
        pageNum: this.searchValue.pageNum,
        pageSize: this.searchValue.pageSize,
      });
      if (!GetAppointmentApiRes) return;
      this.tableData = GetAppointmentApiRes.rows;
      this.total = GetAppointmentApiRes.total;
    },

    handleSelectionChange() {},
  },
  components:{
    Addapoint
  }
};
</script>
 
<style lang = "less" scoped>
ul,
li {
  list-style: none;
}
.input {
  width: 100%;
  li {
    width: 360px;
    font-weight: 700;
    display: inline-block;
    margin-bottom: 12px;
    .el-input {
      width: 70%;
    }
  }
  .l_btn {
    width: 160px;
  }
  .el-icon-delete {
    color: #1890ff;
  }
  .el-icon-delete {
    color: #1890ff;
  }
}
.btn {
  width: 100%;
  display: flex;
  justify-content: space-between;
  .btn_l {
    flex: 1;
  }
  .btn_r {
    .el-icon-search {
      width: 30px;
      height: 30px;
      border: 1px solid #dcdfe6;
      border-radius: 50%;
      // background-color: #1890ff;
      text-align: center;
      line-height: 30px;
    }
    .el-icon-refresh {
      width: 30px;
      height: 30px;
      border: 1px solid #dcdfe6;
      border-radius: 50%;
      // background-color: #1890ff;
      text-align: center;
      line-height: 30px;
      margin-left: 10px;
    }
  }
}
</style>